package xyz.xtt.pay.support;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.xtt.pay.api.enums.PayOrderBusinessTypeEnum;
import xyz.xtt.pay.service.IPayOrderOperator;

import java.util.List;

/**
 * 根据{@link PayOrderBusinessTypeEnum}获取对应的{@link IPayOrderOperator}
 *
 * @author dale
 * @date 2025/2/10
 **/
@Component
public class PayOrderOperatorFactory {
    @Autowired
    private List<IPayOrderOperator> operators;

    public IPayOrderOperator getOperator(PayOrderBusinessTypeEnum type) {
        return operators.stream().filter(orderOperator -> orderOperator.canOperateType(type)).findFirst().orElse(null);
    }
}
